﻿using System;
using System.Linq;
using System.Reflection;
using AutoMapper;

namespace Catchbase.Service.Config
{
    public class AutoMapperConfiguration
    {
        public void Configure()
        {
            foreach(var dto in ModelAssembly.GetTypes().Where(t => t.IsClass))
            {

                var bo = Type.GetType(string.Join(".", CoreNamespace, dto.Name));
                if(bo == null || bo.Name == "Catch") continue;
                Mapper.CreateMap(dto, bo);
                Mapper.CreateMap(bo, dto).ForMember("Catchlist", m => m.Ignore()); ;
            }
        }

        private static string CoreNamespace
        {
            get { return typeof (Model.Catch).Namespace; }
        }

        protected Assembly ModelAssembly
        {
            get { return Assembly.GetAssembly(typeof(Catchbase.Model.Catch)); }
        }
    }
}